<?php

class ClassifyCountAction extends Action {
  function _initialize() {

  }

  public function index() {
    echo "a_hy，a_zy，a_region中的law_count字段初始化功能，目的是修正由于添加新纪录的时候遗忘更新这些表格的bug。<br>请注意，执行该功能会消耗大量的MYSQL性能，日间不要执行<br>";
    echo "<form action='classifyCount/initCount/'><input type='submit' value='开始初始化' /></form>";
  }

  public function initCount() {
    set_time_limit(300001);
    echo "现在开始初始化~~~~<br>";
    echo "初始化a_hy表中的law_count<br>";
    $m = M("");
    $sql = "update a_hy t1 set law_count = (select count(*) from a_law t2 where t1.id = t2.hy_id);";
    $m->execute($sql);
    $sql = "select * from a_hy where did = 0";
    $list = $m->query($sql);
    foreach ($list as $key => $value) {
      $sql = "select sum(law_count) as count from a_hy where did = ".$value["id"];
      $count = $m->query($sql);
      $sql = "update a_hy set law_count = ".$count[0]["count"]." where id = ".$value["id"];
      $m->execute($sql);
    }
    echo "初始化a_hy表中的law_count字段结束<br>";


    echo "初始化a_zy表中的law_count<br>";
    $sql = "update a_zy t1 set law_count = (select count(*) from a_law t2 where t1.id = t2.zy_id);";
    $m->execute($sql);
    $sql = "select * from a_zy where did = 0";
    $list = $m->query($sql);
    foreach ($list as $key => $value) {
      $sql = "select sum(law_count) as count from a_zy where did = ".$value["id"];
      $count = $m->query($sql);
      $sql = "update a_zy set law_count = ".$count[0]["count"]." where id = ".$value["id"];
      $m->execute($sql);
    }
    echo "初始化a_zy表中的law_count字段结束<br>";


    echo "初始化a_region表中的law_count<br>";
    $sql = "update a_region t1 set law_count = (select count(*) from a_law t2 where t1.id = t2.dq_id);";
    $m->execute($sql);
    echo "初始化a_zy表中的law_count字段结束<br>";


    
  }


  
}
?>
